package org.sxf.app.sign.widgt;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import org.sxf.app.sign.R;


public class LoadingDialog extends Dialog {
    private Context mContext = null;
    private Dialog mDialog = null;
    private TextView mTipTextView = null;

    public LoadingDialog(Context context, String src){
        super(context);
        this.mContext = context;
        mDialog = createDialog(src);
    }

    private Dialog createDialog(String msg){
        LayoutInflater inflater = LayoutInflater.from(mContext);
        View v = inflater.inflate(R.layout.loading_dialog, null);// 得到加载view
        LinearLayout layout = (LinearLayout) v.findViewById(R.id.dialog_view);// 加载布局
        // main.xml中的ImageView
        ImageView spaceshipImage = (ImageView) v.findViewById(R.id.img);
        mTipTextView = (TextView) v.findViewById(R.id.loading_tipTextView);// 提示文字
        // 加载动画
        Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(
                mContext, R.anim.loading_animation);
        // 使用ImageView显示动画
        spaceshipImage.startAnimation(hyperspaceJumpAnimation);
        mTipTextView.setText(msg);// 设置加载信息

        Dialog loadingDialog = new Dialog(mContext, R.style.loading_dialog);// 创建自定义样式dialog

        loadingDialog.setCancelable(false);// 不可以用“返回键”取消
        loadingDialog.setContentView(layout, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT));// 设置布局
        return loadingDialog;
    }
    public void startLoadingDialog(){
        mDialog.show();
    }

    public void stopLoadingDialog(){
        if (mDialog != null){
            mDialog.dismiss();
            mDialog = null;
        }
    }

    public void setTipText(String msgStr){
        mTipTextView.setText(msgStr);
    }

}
